/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sembr.vtk.data.input;

import vtk.vtkDoubleArray;
import vtk.vtkPolyData;
import vtk.vtkRegularPolygonSource;

/**
 *
 * @author adriano
 */
public class Circle extends SourceBase {
    
    private double radius;
    private double[] center;
    private vtkRegularPolygonSource circleSource;
    private vtkPolyData triangulatedCircle;
    
    public Circle(double radius, double[] center) {
        this.radius = radius;
        this.center = center;
        setCircleSource(new vtkRegularPolygonSource());
        triangulateCircleSource();
        
    }
    
    /**
     * @return the radius
     */
    public double getRadius() {
        return radius;
    }

    /**
     * @param radius the radius to set
     */
    public void setRadius(double radius) {
        this.radius = radius;
    }

    /**
     * @return the center
     */
    public double[] getCenter() {
        return center;
    }

    /**
     * @param center the center to set
     */
    public void setCenter(double[] center) {
        this.center = center;
    }

    /**
     * @return the circleSource
     */
    public vtkRegularPolygonSource getCircleSource() {
        return circleSource;
    }

    /**
     * @param circleSource the circleSource to set
     */
    private void setCircleSource(vtkRegularPolygonSource circleSource) {
        this.circleSource = circleSource;
        this.circleSource.SetRadius(this.radius);
        this.circleSource.SetCenter(this.center);
        this.circleSource.SetNormal(0., 1., 0.);
        this.circleSource.SetNumberOfSides(60);
        this.circleSource.GeneratePolylineOff();
        this.circleSource.Update();
    }
    
    private void triangulateCircleSource() {        
        triangulatedCircle = super.refineWaveGuideMesh(circleSource.GetOutput(), 3);
        triangulatedCircle.Update();
    }
    
    public void setMaterial(double dieletric) {
        int nrOfCells = triangulatedCircle.GetNumberOfCells(); 
        vtkDoubleArray scalars = new vtkDoubleArray();
        //scalars.SetName("air");
        scalars.SetNumberOfComponents(1);
        scalars.SetNumberOfValues(nrOfCells);
        
        for (int i = 0; i < nrOfCells; i++) {
            scalars.SetValue(i, dieletric);
        }
        
        triangulatedCircle.GetCellData().SetScalars(scalars);
        triangulatedCircle.Update();
    }
    
    @Override
    public vtkPolyData getPolyData() {
        return triangulatedCircle;
    }
}
